#[derive(Debug)]
enum IpAddrKind {
    V4,
    V6
}

fn parse(s: &str) -> IpAddrKind {
    match s {
        "4" => IpAddrKind::V4,
        "6" => IpAddrKind::V6,
        _ => panic!("not found"),
    }
}

fn s() {
    let a = "a/b/c";
    let (start, end) = match a.find('/') {
        Some(s) => {
            println!("Find / at {}", s);
            (0, s)
        }
        None => {
            (1, 2)
        }
    };
    println!("{}, {}", start, end);
}

fn option() {
    // Some内置一类型。
    let s = Some(3);
    println!("some:{:?}", s);

    // 使用match判断类型
    // 不需要返回值时，不需要加分号
    match s {
        Some(i) => { println!("Is {}", i); },
        None => { println!("Is None"); },
    }
    println!("v4 is {}", IpAddrKind::V4 as usize);

    // 有返回值时，返回值类型要一致。
    let r = match s {
        Some(i) => { println!("Is {}", i); i},
        None => { println!("Is None"); 0},
    };

    println!("Result: {}", r);
}

fn main() {
    println!("Hello, world!");
    let four = IpAddrKind::V4;
    println!("v4:{:?}", four);

    option();
    s();
    parse("4");
    // panic
    parse("8");
}
